package com.css.fxfzaqbz.modules.estimate.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzaqbz.modules.assessplot.entity.EvaluationResults;
import com.css.fxfzaqbz.modules.assessplot.service.EvaluationResultsService;
import com.css.fxfzaqbz.modules.estimate.entity.Fault;
import com.css.fxfzaqbz.modules.estimate.entity.InstrumentCatalog;
import com.css.fxfzaqbz.modules.estimate.entity.StratumLithology;
import com.css.fxfzaqbz.modules.estimate.entity.StrongCatalog;
import com.css.fxfzaqbz.modules.estimate.repository.FaultRepository;
import com.css.fxfzaqbz.modules.estimate.repository.InstrumentCatalogRepository;
import com.css.fxfzaqbz.modules.estimate.repository.StratumLithologyRepository;
import com.css.fxfzaqbz.modules.estimate.repository.StrongCatalogRepository;
import com.css.fxfzaqbz.modules.estimate.service.StructureService;
import com.css.fxfzaqbz.modules.supergraph.exception.CustomException;
import com.css.fxfzaqbz.util.RestTemplateUtil;
import com.css.fxfzaqbz.util.UUIDGenerator;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.geotools.data.FeatureWriter;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.shapefile.ShapefileDataStoreFactory;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.referencing.CRS;
import org.locationtech.jts.geom.MultiLineString;
import org.opengis.feature.simple.SimpleFeature;
import org.slw.common.helper.PropsHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

@Service
public class StructureServiceImpl implements StructureService {
    @Autowired
    private FaultRepository faultRepository;
    @Autowired
    private InstrumentCatalogRepository instrumentCatalogRepository;
    @Autowired
    private StratumLithologyRepository stratumLithologyRepository;
    @Autowired
    private StrongCatalogRepository strongCatalogRepository;
    @Autowired
    RestTemplateUtil restTemplateUtil;
    @Autowired
    private EvaluationResultsService evaluationResultsService;
    @Value("${image.localDir}")
    private String localDir;


    @Override
    public void save(String iaId, String dataVersion, String dataVersion1, String dataVersion2, String dataVersion3) {
        Properties configGroup = PropsHelper.loadProps("slw-config.properties");
        String uuid = UUIDGenerator.getUUID();
        //断层数据
        String url1 = configGroup.getProperty("restTemplateUrl") + "/aqbz/getFaults";
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("dataVersion", dataVersion);
        ResponseEntity<String> cchResponseEntity1 = restTemplateUtil.sendHttpRequestPj(url1, paramMap);
        List<Fault> list1 = JSONObject.parseArray(cchResponseEntity1.getBody(), Fault.class);
        if (list1.size() == 0) throw new CustomException("该版本下没有数据");
        list1 = list1.stream().map(item -> {
            item.setResultAnalysis(uuid);
            return item;
        }).collect(Collectors.toList());
        faultRepository.batchSave(list1);
        //1970年以来小震目录（点属性）
        String url2 = configGroup.getProperty("restTemplateUrl") + "/aqbz/getHistoryA";
        Map<String, Object> paramMap1 = new HashMap<>();
        paramMap1.put("dataVersion", dataVersion1);
        ResponseEntity<String> cchResponseEntity2 = restTemplateUtil.sendHttpRequestPj(url2, paramMap1);
        List<InstrumentCatalog> list2 = JSONObject.parseArray(cchResponseEntity2.getBody(), InstrumentCatalog.class);
        if (list2.size() == 0) throw new CustomException("该版本下没有数据");
        list2 = list2.stream().map(item -> {
            item.setResultAnalysis(uuid);
            return item;
        }).collect(Collectors.toList());
        instrumentCatalogRepository.batchSave(list2);
        //历史4 3/4以上强震目录（点属性）
        String url3 = configGroup.getProperty("restTemplateUrl") + "/aqbz/getHistoryB";
        Map<String, Object> paramMap2 = new HashMap<>();
        paramMap2.put("dataVersion", dataVersion2);
        ResponseEntity<String> cchResponseEntity3 = restTemplateUtil.sendHttpRequestPj(url3, paramMap2);
        List<StrongCatalog> list3 = JSONObject.parseArray(cchResponseEntity3.getBody(), StrongCatalog.class);
        if (list3.size() == 0) throw new CustomException("该版本下没有数据");
        list3 = list3.stream().map(item -> {
            item.setResultAnalysis(uuid);
            return item;
        }).collect(Collectors.toList());
        strongCatalogRepository.batchSave(list3);
        //地层岩性 （面属性）
        String url4 = configGroup.getProperty("restTemplateUrl") + "/aqbz/getLithology";
        Map<String, Object> paramMap3 = new HashMap<>();
        paramMap3.put("dataVersion", dataVersion3);
        ResponseEntity<String> cchResponseEntity4 = restTemplateUtil.sendPostHttpRequest1(url4, paramMap3);
        List<StrongCatalog> list4 = JSONObject.parseArray(cchResponseEntity4.getBody(), StrongCatalog.class);
        if (list4.size() == 0) throw new CustomException("该版本下没有数据");
        list4 = list4.stream().map(item -> {
            item.setResultAnalysis(uuid);
            return item;
        }).collect(Collectors.toList());
        stratumLithologyRepository.batchSave(list4);

        EvaluationResults results = buildEvaluationResults(iaId, uuid);
        evaluationResultsService.save(results);
    }


    @Override
    public void downLoadShp(String resultAnalysis, HttpServletResponse response) throws Exception {
        String millis = System.currentTimeMillis() + "";
        File file = new File(localDir + File.separator + "zip");
        if (!file.exists()) file.mkdirs();
        ArrayList<String> list = new ArrayList<String>();
        //断层数据
        List<Fault> faultList = faultRepository.getList(resultAnalysis);
        if (faultList.size() != 0) {
            String path1 = downLoadShp1(faultList, file, millis);
            list.add(path1);
        }
        //1970年以来小震数据
        List<InstrumentCatalog> instrumentCatalogList = instrumentCatalogRepository.getList(resultAnalysis);
        if (instrumentCatalogList.size() != 0) {
            String path2 = downLoadShp2(instrumentCatalogList, file, millis);
            list.add(path2);
        }
        //历史4 3/4以上强震
        List<StrongCatalog> strongCatalogList = strongCatalogRepository.getList(resultAnalysis);
        if (strongCatalogList.size() != 0) {
            String path3 = downLoadShp3(strongCatalogList, file, millis);
            list.add(path3);
        }
        //地层岩性（面属性）
        List<StratumLithology> stratumLithologyList = stratumLithologyRepository.getList(resultAnalysis);
        if (stratumLithologyList.size() != 0) {
//            String path4 = downLoadShp4(stratumLithologyList, file, millis);
//            list.add(path4);
        }
        String zipName = "地震构造数据" + millis;
        String zipPath = file + File.separator + zipName + ".zip";
        File zipFile = new File(zipPath);
        InputStream input = null;
        ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
        // zip的名称为
        zipOut.setComment(zipName);
        String[] shpFiles = list.toArray(new String[list.size()]);
        for (int i = 0; i < shpFiles.length; i++) {
            File file1 = new File(shpFiles[i]);
            input = new FileInputStream(file1);
            zipOut.putNextEntry(new ZipEntry(file1.getName()));
            int temp = 0;
            while ((temp = input.read()) != -1) {
                zipOut.write(temp);
            }
            input.close();
        }
        zipOut.close();

        //拼接下载默认名称并转为ISO-8859-1格式
        String fileName = new String((zipName + ".zip").getBytes(), StandardCharsets.ISO_8859_1);
        response.setHeader("Content-Disposition", "attchment;filename=" + fileName);
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Method", "POST,GET");
        //该流不可以手动关闭,手动关闭下载会出问题,下载完成后会自动关闭
        ServletOutputStream outputStream = response.getOutputStream();
        FileInputStream inputStream = new FileInputStream(zipPath);
        // copy方法为文件复制,在这里直接实现了下载效果
        IOUtils.copy(inputStream, outputStream);
        // 关闭输入流
        inputStream.close();
        //删除中间文件
        File[] files = file.listFiles();
        for (File file2 : files) {
            if (file2.getName().contains(millis)) file2.delete();
        }
    }

    private String downLoadShp3(List<StrongCatalog> list, File file, String millis) throws Exception{
        //创建文件路径
        String name = "历史4 3/4以上强震数据" + millis;
        String path = file + File.separator + name + ".shp";
        File file1 = new File(path);
        //添加创建的路径
        Map params = new HashMap();
        params.put(ShapefileDataStoreFactory.URLP.key, file1.toURI().toURL());
        ShapefileDataStoreFactory sf = new ShapefileDataStoreFactory();
        //创建shape文件数据仓库根据工厂
        ShapefileDataStore ds = (ShapefileDataStore) sf.createDataStore(file1.toURI().toURL());
        ds.setCharset(StandardCharsets.UTF_8);
        //创建要素模板
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.setCRS(CRS.decode("EPSG:4490"));
        //设置全局状态
        tb.setName("shapefile");
        //添加属性类型
        tb.add("省", String.class);
        tb.add("市", String.class);
        tb.add("区/县", String.class);
        tb.add("乡镇", String.class);
        tb.add("地震编号", String.class);
        tb.add("地震事件名称（简称）", String.class);
        tb.add("日期", String.class);
        tb.add("时间", String.class);
        tb.add("参考地名", String.class);
        tb.add("经度", Double.class);
        tb.add("纬度", Double.class);
        tb.add("震级", Double.class);
        tb.add("震源深度", Double.class);
        tb.add("宏观震中烈度(极震区)", Double.class);
        tb.add("等震线图", String.class);
        tb.add("震中烈度", String.class);
        tb.add("精度", String.class);
        tb.add("符号或标注旋转角度", String.class);
        tb.add("备注", String.class);

        tb.add("the_geom", MultiLineString.class);
        ds.createSchema(tb.buildFeatureType());
        //设置编码格式
        FeatureWriter featureWriter = ds.getFeatureWriter(ds.getTypeNames()[0], null);
        for (StrongCatalog entity : list) {
            SimpleFeature feature = (SimpleFeature) featureWriter.next();
            feature.setAttribute(1, entity.getProvince());
            feature.setAttribute(2, entity.getCity());
            feature.setAttribute(17, entity.getAccuracy());
            feature.setAttribute(18, entity.getCommentInfo());
            feature.setAttribute("the_geom", entity.getGeom());
        }
        featureWriter.write();
        featureWriter.close();
        ds.dispose();

        try {
            File file3 = new File(file + File.separator + name + ".cpg");
            DataOutputStream dos = new DataOutputStream(new FileOutputStream(file3));
            dos.write("UTF-8".getBytes());
            dos.close();
            String zipPath = file + File.separator + name + ".zip";
            File zipFile = new File(zipPath);
            InputStream input = null;
            ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
            // zip的名称为
            zipOut.setComment(name);
            String[] shpFiles = new String[]{
                    file + File.separator + name + ".dbf",
                    file + File.separator + name + ".prj",
                    file + File.separator + name + ".shp",
                    file + File.separator + name + ".shx",
                    file + File.separator + name + ".fix",
                    file + File.separator + name + ".cpg",
            };
            for (int i = 0; i < shpFiles.length; i++) {
                File file2 = new File(shpFiles[i]);
                input = new FileInputStream(file2);
                zipOut.putNextEntry(new ZipEntry(file2.getName()));
                int temp = 0;
                while ((temp = input.read()) != -1) {
                    zipOut.write(temp);
                }
                input.close();
            }
            zipOut.close();
            return zipPath;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private String downLoadShp2(List<InstrumentCatalog> list, File file, String millis) throws Exception {
        //创建文件路径
        String name = "1970年以来小震数据" + millis;
        String path = file + File.separator + name + ".shp";
        File file1 = new File(path);
        //添加创建的路径
        Map params = new HashMap();
        params.put(ShapefileDataStoreFactory.URLP.key, file1.toURI().toURL());
        ShapefileDataStoreFactory sf = new ShapefileDataStoreFactory();
        //创建shape文件数据仓库根据工厂
        ShapefileDataStore ds = (ShapefileDataStore) sf.createDataStore(file1.toURI().toURL());
        ds.setCharset(StandardCharsets.UTF_8);
        //创建要素模板
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.setCRS(CRS.decode("EPSG:4490"));
        //设置全局状态
        tb.setName("shapefile");
        //添加属性类型
        tb.add("省", String.class);
        tb.add("市", String.class);
        tb.add("区/县", String.class);
        tb.add("乡镇", String.class);
        tb.add("地震编号", String.class);
        tb.add("地震事件名称（简称）", String.class);
        tb.add("日期", String.class);
        tb.add("时间", String.class);
        tb.add("参考地名", String.class);
        tb.add("经度", Double.class);
        tb.add("纬度", Double.class);
        tb.add("震级", Double.class);
        tb.add("震源深度", Double.class);
        tb.add("宏观震中烈度(极震区)", Double.class);
        tb.add("等震线图", String.class);
        tb.add("震中烈度", String.class);
        tb.add("精度", String.class);
        tb.add("符号或标注旋转角度", String.class);
        tb.add("备注", String.class);

        tb.add("the_geom", MultiLineString.class);
        ds.createSchema(tb.buildFeatureType());
        //设置编码格式
        FeatureWriter featureWriter = ds.getFeatureWriter(ds.getTypeNames()[0], null);
        for (InstrumentCatalog entity : list) {
            SimpleFeature feature = (SimpleFeature) featureWriter.next();
            feature.setAttribute(1, entity.getProvince());
            feature.setAttribute(2, entity.getCity());
            feature.setAttribute(3, entity.getCounty());
            feature.setAttribute(4, entity.getTown());
            feature.setAttribute(5, entity.getEarthquakeCode());
            feature.setAttribute(6, entity.getEventAbbreviation());
            feature.setAttribute(7, entity.getOccurrencedate());
            feature.setAttribute(8, entity.getOccurrencetime());
            feature.setAttribute(9, entity.getLocation());
            feature.setAttribute(10, entity.getJicLongitude());
            feature.setAttribute(11, entity.getJicLatitude());
            feature.setAttribute(12, entity.getMagnitude());
            feature.setAttribute(13, entity.getDepth());
            feature.setAttribute(14, entity.getEpicenter());
            feature.setAttribute(15, entity.getIsoline());
            feature.setAttribute(16, entity.getEpicentralIntensity());
            feature.setAttribute(17, entity.getAccuracy());
            feature.setAttribute(18, entity.getCommentInfo());
            feature.setAttribute("the_geom", entity.getGeom());
        }
        featureWriter.write();
        featureWriter.close();
        ds.dispose();

        try {
            File file3 = new File(file + File.separator + name + ".cpg");
            DataOutputStream dos = new DataOutputStream(new FileOutputStream(file3));
            dos.write("UTF-8".getBytes());
            dos.close();
            String zipPath = file + File.separator + name + ".zip";
            File zipFile = new File(zipPath);
            InputStream input = null;
            ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
            // zip的名称为
            zipOut.setComment(name);
            String[] shpFiles = new String[]{
                    file + File.separator + name + ".dbf",
                    file + File.separator + name + ".prj",
                    file + File.separator + name + ".shp",
                    file + File.separator + name + ".shx",
                    file + File.separator + name + ".fix",
                    file + File.separator + name + ".cpg",
            };
            for (int i = 0; i < shpFiles.length; i++) {
                File file2 = new File(shpFiles[i]);
                input = new FileInputStream(file2);
                zipOut.putNextEntry(new ZipEntry(file2.getName()));
                int temp = 0;
                while ((temp = input.read()) != -1) {
                    zipOut.write(temp);
                }
                input.close();
            }
            zipOut.close();
            return zipPath;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private String downLoadShp1(List<Fault> faultList, File file, String millis) throws Exception {
        //创建文件路径
        String name = "断层分布数据" + millis;
        String path = file + File.separator + name + ".shp";
        File file1 = new File(path);
        //添加创建的路径
        Map params = new HashMap();
        params.put(ShapefileDataStoreFactory.URLP.key, file1.toURI().toURL());
        ShapefileDataStoreFactory sf = new ShapefileDataStoreFactory();
        //创建shape文件数据仓库根据工厂
        ShapefileDataStore ds = (ShapefileDataStore) sf.createDataStore(file1.toURI().toURL());
        ds.setCharset(StandardCharsets.UTF_8);
        //创建要素模板
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.setCRS(CRS.decode("EPSG:4490"));
        //设置全局状态
        tb.setName("shapefile");
        //添加属性类型
        tb.add("断层编号", String.class);
        tb.add("工作底图比例尺（分母）", Double.class);
        tb.add("断裂带名称", String.class);
        tb.add("断层名称", String.class);
        tb.add("断层段名称", String.class);
        tb.add("走向 [16方位]", Integer.class);
        tb.add("断层走向 [度]", Double.class);
        tb.add("倾向 [16方位]", Integer.class);
        tb.add("倾角 [度]", Double.class);
        tb.add("长度", String.class);
        tb.add("上断点埋深 [米]", String.class);
        tb.add("破碎带宽度 [米]", String.class);
        tb.add("变形带宽度 [米]", String.class);
        tb.add("断层性质", Integer.class);
        tb.add("最新活动时代", Integer.class);
        tb.add("位移与平均速率起算时间", String.class);
        tb.add("垂直位移 [米]", Double.class);
        tb.add("垂直位移误差", Double.class);
        tb.add("走向水平位移 [米]", Double.class);
        tb.add("走向水平位移误差", Double.class);
        tb.add("水平//张缩位移 [米]", Double.class);
        tb.add("水平张缩位移误差", Double.class);
        tb.add("平均垂直速率 [毫米/年]", Double.class);
        tb.add("平均垂直速率误差", Double.class);
        tb.add("平均水平速率 [毫米/年]", Double.class);
        tb.add("平均水平速率误差", Double.class);
        tb.add("最新速率起算时间", String.class);
        tb.add("最新垂直速率 [毫米/年]", Double.class);
        tb.add("最新垂直速率误差", Double.class);
        tb.add("最新水平速率 [毫米/年]", Double.class);
        tb.add("最新水平速率误差", Double.class);
        tb.add("最大垂直速率 [米]", Double.class);
        tb.add("最大垂直速率误差", Double.class);
        tb.add("最大水平速率 [毫米/年]", Double.class);
        tb.add("最大水平速率误差", Double.class);
        tb.add("古地震事件次数", Integer.class);
        tb.add("古地震复发间隔", Double.class);
        tb.add("古地震复发间隔上限", Double.class);
        tb.add("确定手段", String.class);
        tb.add("最大破裂长度", Double.class);
        tb.add("平均破裂长度", Double.class);
        tb.add("最晚地震离逝时间", String.class);
        tb.add("错动深度", Double.class);
        tb.add("错动深度误差", Double.class);
        tb.add("平均滑动速率 [毫米/年]", Double.class);
        tb.add("平均滑动速率误差", Double.class);
        tb.add("蠕动速率 [毫米/年]", Double.class);
        tb.add("蠕动速率误差", Double.class);
        tb.add("最大同震位移 [米]", Double.class);
        tb.add("最大同震位移误差", Double.class);
        tb.add("平均同震位移 [米]", Double.class);
        tb.add("平均同震位移误差", Double.class);
        tb.add("最新地震平均位移", Double.class);
        tb.add("最新地震平均位移误差", Double.class);
        tb.add("断层符号基础位", String.class);
        tb.add("断层符号下标位", String.class);
        tb.add("断层符号上标位", String.class);
        tb.add("断层显示码", String.class);
        tb.add("活断层探测研究状况  是否做过活断层探测：1(是)、0(否)", String.class);
        tb.add("隐伏/出露", String.class);
        tb.add("活动时代", String.class);
        tb.add("备注", String.class);
        tb.add("the_geom", MultiLineString.class);
        ds.createSchema(tb.buildFeatureType());
        //设置编码格式
        FeatureWriter featureWriter = ds.getFeatureWriter(ds.getTypeNames()[0], null);
        for (Fault entity : faultList) {
            SimpleFeature feature = (SimpleFeature) featureWriter.next();
            feature.setAttribute(1, entity.getJfCode());
            feature.setAttribute(2, entity.getScale());
            feature.setAttribute(3, entity.getFractureZoneName());
            feature.setAttribute(4, entity.getDcName());
            feature.setAttribute(5, entity.getFaultSegmentName());
            feature.setAttribute(6, entity.getStrikeDrection());
            feature.setAttribute(7, entity.getStrike());
            feature.setAttribute(8, entity.getDirection());
            feature.setAttribute(9, entity.getClination());
            feature.setAttribute(10, entity.getJfLength());
            feature.setAttribute(11, entity.getTopDepth());
            feature.setAttribute(12, entity.getWidth());
            feature.setAttribute(13, entity.getFractureBeltWidth());
            feature.setAttribute(14, entity.getFeature());
            feature.setAttribute(15, entity.getLatestActivePeriod());
            feature.setAttribute(16, entity.getStartTimeEst());
            feature.setAttribute(17, entity.getVdisplaceEst());
            feature.setAttribute(18, entity.getVdisplaceEr());
            feature.setAttribute(19, entity.getHdisplaceEst());
            feature.setAttribute(20, entity.getHdisplaceEr());
            feature.setAttribute(21, entity.getTdisplaceEst());
            feature.setAttribute(22, entity.getTdisplaceEr());
            feature.setAttribute(23, entity.getAveVrate());
            feature.setAttribute(24, entity.getAveVrateEr());
            feature.setAttribute(25, entity.getAveHrate());
            feature.setAttribute(26, entity.getAveHrateRr());
            feature.setAttribute(27, entity.getStartTimeNewest());
            feature.setAttribute(28, entity.getNewVrate());
            feature.setAttribute(29, entity.getNewVrateer());
            feature.setAttribute(30, entity.getNewHrate());
            feature.setAttribute(31, entity.getNewHrateer());
            feature.setAttribute(32, entity.getMaxVrate());
            feature.setAttribute(33, entity.getMaxVrateEr());
            feature.setAttribute(34, entity.getMaxHrate());
            feature.setAttribute(35, entity.getMaxHrateRr());
            feature.setAttribute(36, entity.getEqEventCount());
            feature.setAttribute(37, entity.getEqEventRibottom());
            feature.setAttribute(38, entity.getEqEventRitop());
            feature.setAttribute(39, entity.getMethod());
            feature.setAttribute(40, entity.getMaxRuptureLen());
            feature.setAttribute(41, entity.getAvgRuptureLen());
            feature.setAttribute(42, entity.getElapseTimeLatesteq());
            feature.setAttribute(43, entity.getSlipDepthEst());
            feature.setAttribute(44, entity.getSlipDepthEr());
            feature.setAttribute(45, entity.getAvgSlipRateest());
            feature.setAttribute(46, entity.getAvgSlipRateer());
            feature.setAttribute(47, entity.getCreepRateest());
            feature.setAttribute(48, entity.getCreepRateer());
            feature.setAttribute(49, entity.getCsMaxSlipest());
            feature.setAttribute(50, entity.getCsMaxSliper());
            feature.setAttribute(51, entity.getCsAveSlipest());
            feature.setAttribute(52, entity.getCsAveSliper());
            feature.setAttribute(53, entity.getLatestCsSlipest());
            feature.setAttribute(54, entity.getLatestCsSliper());
            feature.setAttribute(55, entity.getNsb1());
            feature.setAttribute(56, entity.getNsb2());
            feature.setAttribute(57, entity.getNsb3());
            feature.setAttribute(58, entity.getShowCode());
            feature.setAttribute(59, entity.getActiveFault());
            feature.setAttribute(60, entity.getStatus());
            feature.setAttribute(61, entity.getActivePeriod());
            feature.setAttribute(62, entity.getCommentInfo());
            feature.setAttribute("the_geom", entity.getGeom());
        }
        featureWriter.write();
        featureWriter.close();
        ds.dispose();

        try {
            File file3 = new File(file + File.separator + name + ".cpg");
            DataOutputStream dos = new DataOutputStream(new FileOutputStream(file3));
            dos.write("UTF-8".getBytes());
            dos.close();
            String zipPath = file + File.separator + name + ".zip";
            File zipFile = new File(zipPath);
            InputStream input = null;
            ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
            // zip的名称为
            zipOut.setComment(name);
            String[] shpFiles = new String[]{
                    file + File.separator + name + ".dbf",
                    file + File.separator + name + ".prj",
                    file + File.separator + name + ".shp",
                    file + File.separator + name + ".shx",
                    file + File.separator + name + ".fix",
                    file + File.separator + name + ".cpg",
            };
            for (int i = 0; i < shpFiles.length; i++) {
                File file2 = new File(shpFiles[i]);
                input = new FileInputStream(file2);
                zipOut.putNextEntry(new ZipEntry(file2.getName()));
                int temp = 0;
                while ((temp = input.read()) != -1) {
                    zipOut.write(temp);
                }
                input.close();
            }
            zipOut.close();
            return zipPath;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private EvaluationResults buildEvaluationResults(String iaId, String uuid) {
        EvaluationResults results = new EvaluationResults();
        results.setId(uuid);
        results.setIaId(iaId);
        results.setResult("4");
        return results;
    }
}
